#!/usr/bin/env python3
# -*- coding: utf-8 -*-

data = 'abcevaefegsgdghfdefavbdr'

# 统计data中每个元素出现的次数
stat_dict = {}
for d in data:
    stat_dict[d] = stat_dict.get(d, 0) + 1
print(stat_dict)

# 根据data元素出现的次数, 降序排列, 列出出现做多的三个元素
stat_dict = {}
for d in data:
    stat_dict[d] = stat_dict.get(d, 0) + 1
print(
    dict(sorted(stat_dict.items(), key=lambda x: x[1],
                reverse=True)[:3]).keys())
